<extend name="./public/frame.html"/>
<block name="content">
	<blockquote class="layui-elem-quote search">
		<div class="layui-inline">
			<input type="text" name="activity_name" id="activity_name" placeholder="活动名称" class="layui-input">
		</div>
		<div class="layui-inline">
			<input type="text" class="layui-input" id="start_time" placeholder="活动开始时间" style="width: 120px;">
		</div>
		<div class="layui-inline">
			<input type="text" class="layui-input" id="end_time" placeholder="活动结束时间" style="width: 120px;">
		</div>
		<div class="layui-inline">
			<input type="text" class="layui-input" id="start" placeholder="到账开始时间" style="width: 120px;">
		</div>
		<div class="layui-inline">
			<input type="text" class="layui-input" id="end" placeholder="到账结束时间" style="width: 120px;">
		</div>
		<div class="layui-inline">
			<select id="activity_model" name="activity_model" class="layui-input"lay-filter="activity_model" style="width: 150px;">
				<option value="">活动类型</option>
				<?php foreach($acitivetyType as $key=>$value):?>
				<option value="<?php echo $key;?>"><?php echo $value;?></option>
				<?php endforeach;?>
			</select>
		</div>
		<div class="layui-inline">
			<select id="order_type" name="order_type" class="layui-input"lay-filter="order_type" style="width: 120px;">
				<option value="">所属活动</option>
				<?php foreach($order_type as $key=>$value):?>
				<option value="<?php echo $key;?>"><?php echo $value;?></option>
				<?php endforeach;?>
				<option value="0">不限</option>
			</select>
		</div>
		<div class="layui-inline">
			<select id="user_type" name="user_type" class="layui-input"lay-filter="user_type" style="width: 120px;">
				<option value="">活动对象</option>
				<?php foreach($terminal as $key=>$value):?>
				<option value="<?php echo $key;?>"><?php echo $value;?></option>
				<?php endforeach;?>
			</select>
		</div>
		<div class="layui-inline">
			<input type="text" name="phone" id="phone" placeholder="手机号" class="layui-input" style="width: 120px;">
		</div>
		<div class="layui-inline">
			<input type="text" name="order_sn" id="order_sn" placeholder="订单号" class="layui-input">
		</div>
		<div class="layui-inline">
			<select name="province_id" id="province_id" class="layui-input" lay-filter="province" style="width: 150px;" onclick="getProvinceList();">
				<option value="">请选择省份</option>
				<?php foreach($provinceList as $key=>$value):?>
				<option value="<?php echo $value['region_id'];?>"><?php echo $value['region_name'];?></option>
				<?php endforeach;?>
			</select>
		</div>
		<div class="layui-inline">
			<select name="city_id" id="city_id" class="layui-input" lay-filter="city_id" style="width: 120px;">
				<option value="">请选择城市</option>
			</select>
		</div>
		<div class="layui-inline">
			<button class="layui-btn" data-type="search">搜索</button>
		</div>
		<div class="layui-inline">
			<button class="layui-btn layui-btn-warm" data-type="excel" style="width: 100px;">导出数据</button>
		</div>
	</blockquote>
	<div class="row" style="padding-left: 20px;padding-top: 5px;padding-bottom: 5px;">
		<div class="layui-inline">
			&nbsp;&nbsp;奖励总额：
			<span class="sumMoney"><?php echo $sumMoney;?></span>
			&nbsp;&nbsp;
			<span class="daoSumMoney"><?php echo $daoZhangSumMoney;?></span>（<span style="color: green;">到账</span>）
			&nbsp;&nbsp;
			<span class="noSumMoney"><?php echo $noZhangSumMoney;?></span>（<span style="color: red;">未到账</span>）
		</div>
	</div>
	<table class="layui-table" lay-data="{width:'auto', height:'auto', url:'{$url}', page: true, limit: 10, id:'AdminActivity'}" lay-filter="AdminActivity">
		<thead>
		<tr>
			<th lay-data="{field:'id', width:80,fixed: true, sort: true,align:'center'}">ID</th>
			<th lay-data="{field:'activity_name', width:160,align:'center'}">活动名称</th>
			<th lay-data="{field:'activity_model', width:140,align:'center'}">活动类型</th>
			<th lay-data="{field:'user_type', width:100,align:'center'}">活动对象</th>
			<th lay-data="{field:'order_type', width:100,align:'center'}">所属活动</th>
			<th lay-data="{field:'time', width:190,align:'center'}">活动时间(开始 / 结束)</th>
			<th lay-data="{field:'region_name', width:100,align:'center'}">城市</th>
			<th lay-data="{field:'phone', width:120,align:'center'}">奖励用户</th>
			<th lay-data="{field:'amount', width:100,align:'center'}">金额 / 积分</th>
			<th lay-data="{field:'accountStatusNameAly', width:100,align:'center'}">到账状态</th>
			<th lay-data="{field:'account_time', width:160,align:'center'}">到账时间</th>
			<th lay-data="{field:'order_sn', width:190,align:'center'}">订单号</th>
			<th lay-data="{field:'add_time',fixed:'right', width:160, align:'center'}">记录时间</th>
		</tr>
		</thead>
	</table>

	<script>
		layui.use(['form','table','laydate'], function () {
			var table = layui.table,form = layui.form,laydate = layui.laydate;
			laydate.render({
				elem: '#start_time' //指定元素
			});

			laydate.render({
				elem: '#end_time' //指定元素
			});
			laydate.render({
				elem: '#start' //指定元素
			});
			laydate.render({
				elem: '#end' //指定元素
			});
			var active = {
				search: function () {
					var province_id 	= $("#province_id").val();
					var city_id 		= $("#city_id").val();
					var activity_name 	= $("#activity_name").val();
					var start_time 		= $("#start_time").val();
					var end_time 		= $("#end_time").val();
					var order_type		= $("#order_type").val();
					var user_type		= $("#user_type").val();
					var activity_model	= $("#activity_model").val();
					var phone			= $("#phone").val();
					var order_sn		= $("#order_sn").val();
					var start		= $("#start").val();
					var end		= $("#end").val();
					table.reload('AdminActivity', {
						url: '/admin/AdminActivity/table',
						where: {
							"activity_name": activity_name,
							"start_time": start_time,
							"start": start,
							"end_time": end_time,
							"end": end,
							"order_type": order_type,
							"user_type": user_type,
							"activity_model": activity_model,
							"phone": phone,
							"order_sn": order_sn,
							"province_id": province_id,
							"city_id": city_id,
						},
						done: function(res, curr, count){
							$(".sumMoney").html(res.sumMoney);
							$(".daoSumMoney").html(res.daoZhangSumMoney);
							$(".noSumMoney").html(res.noZhangSumMoney);
						}
						/*parseData: function(res){
							$(".sumMoney").html(res.sumMoney)
						}*/
					});
				}, excel: function () {
					var activity_name 	= $("#activity_name").val();
					var start_time 		= $("#start_time").val();
					var end_time 		= $("#end_time").val();
					var order_type		= $("#order_type").val();
					var start		= $("#start").val();
					var end		= $("#end").val();
					var user_type		= $("#user_type").val();
					var activity_model	= $("#activity_model").val();
					var phone			= $("#phone").val();
					var order_sn		= $("#order_sn").val();
					var province_id 	= $("#province_id").val();
					var city_id 		= $("#city_id").val();
					var str = "&activity_name="+activity_name+"&start_time="+start_time+"&end_time="+end_time+"&order_type="+order_type+"&user_type="+user_type+"&activity_model="+activity_model+"&phone="+phone+"&order_sn="+order_sn+"&province_id="+province_id+"&city_id="+city_id+"&start="+start+"&end="+end;
					layer.confirm('确认导出数据:', {
						btn: ['确认', '取消'] //可以无限个按钮
						, btn3: function (index, layero) {
							layer.close(index);
						}
					}, function (index, layero) {
						//按钮【按钮一】的回调
						console.log(str)
						location = "{:url('excel','header=')}?" + str ;
						layer.close(index);
					});
				}
			}
			layui.jquery('.layui-btn').on('click', function () {
				var type = layui.jquery(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
		});
		function getProvinceList(){
			$("#city_id").empty();
			$("#city_id").append('<option value=>请选择城市</option>');
			var province_id = $("#province_id").val();
			$.ajax({
				url:'{:url("/admin/Franchisee/cityList")}',
				async:true,
				//dataType:'json',
				type:'post',
				data:{'province_id':province_id},
				success:function(res){
					$("#city_id").append(res);
				},
				error:function(e){
					layer.msg('请求错误');return false;
				}
			})
		};
	</script>
</block>
